package com.example.xss;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.xss.client.LixingerClient;
import com.example.xss.commom.enums.MetricNameEnum;
import com.example.xss.lixinger.model.IndexAnalysisSource;
import com.example.xss.lixinger.model.MetricDataReq;
import com.example.xss.lixinger.service.LixingerFormService;
import org.junit.jupiter.api.Test;

import javax.websocket.SendResult;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class TTtt {


    @Test
    public void list() {
        List<MetricNameEnum> metricNameEnumList = CollUtil.newArrayList(MetricNameEnum.YYSY,
                MetricNameEnum.YSZK,
                MetricNameEnum.LDBL,
                MetricNameEnum.ZBKZ,
                MetricNameEnum.JLY,
                MetricNameEnum.CH,
                MetricNameEnum.JYHDXJLJE);

        MetricDataReq req = MetricDataReq.builder()
                .stockIds(CollUtil.newArrayList(603989L))
                .startDate("2015-06-30T15:59:59.999Z")
                .endDate("2021-09-29T16:00:00.000Z")
                .metricsNames(metricNameEnumList.stream()
                        .map(MetricNameEnum::getValue).collect(Collectors.toList()))
                .ownerTypes(CollUtil.newArrayList("consolidated"))
                .fsReportTypeFilter("all")
                .granularities(CollUtil.newArrayList("y"))
                .expressionCaculateTypes(CollUtil.newArrayList("t", "c", "c_2y", "c_y2y", "t_c2c", "c_c2c"))
                .build();

        JSONObject json = LixingerClient.getListData(req);
        JSONArray fsMetricsList = json.getJSONArray("fsMetricsList");



    }

    @Test
    public void date() {
        LocalDateTime now = LocalDateTime.now();
        String str = now.toString();
        System.out.println(str);
        LocalDateTime parse = LocalDateTime.parse(str);
        System.out.println(parse.getHour());
        System.out.println(parse.plusYears(-6));
    }
    @Test
    public void dateFormat() {
        String dateStr = "2019-12-30T16:00:00.000Z";
        LocalDateTime parse = LocalDateTime.parse(dateStr.substring(0,dateStr.length()-2));
    }

    @Test
    public void getSourceOfYearTest() {
        List<IndexAnalysisSource> sourceOfYear = LixingerFormService.getSourceOfYear(5, 603989L);
        System.out.println(JSONUtil.toJsonStr(sourceOfYear));
    }

    @Test
    public void indexAnalysisTest() {
        List<IndexAnalysisSource> sourceOfYear = LixingerFormService.getSourceOfYear(5, 603989L);
//        System.out.println(JSONUtil.toJsonStr(LixingerFormService.indexAnalysis(sourceOfYear)));
    }

}
